﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;
using System.Text;

using Gift.DAL;

namespace WebSite.cn
{
    public partial class index : BasePage
    {
        // Fields

        public string hotmsg1 = "";
        public string hotmsg2 = "";
        public string hotmsg3 = "";
        public string hotmsg4 = "";
        public string hotpic1 = "";
        public string hotpic2 = "";
        public string hotpic3 = "";
        public string hotpic4 = "";
        public string hottitle1 = "";
        public string hottitle2 = "";
        public string hottitle3 = "";
        public string hottitle4 = "";
        public string imgAlt = "";
        public string imgLink = "";
        public string imgtext = "";
        public string imgUrl = "";
        public string newsmsg = "";
        public string peipro = "";
        public string pinpai = "";
        public string TopicHtml = "";
        public string BrandHtml = string.Empty;

        public string imgNumber = "";

        DALInstitution theInstitution = new DALInstitution();

        StringBuilder sbCardListHtml = new StringBuilder();

        string sCardHtmlFormat = "   <img src=\"../uploadFile/topic/white.jpg\" width=\"964px\" height=\"1px\" alt=\"\" />"
                                 + " <div class=\"indexTitle\" >"
                                 + " <p>{0}</p>"
                                 + " <h4><a href=\"hotpro.aspx?sid=1\">查看全部>></a></h4>"
                                 + " </div>"
                                 + " <div class=\"pro02\"> "
                                 + " <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"table_pro\">"
                                 + "   <tr>{1}</tr>"
                                 + "   </table>"
                                 + "  </div> ";


        // Methods
        private void Bind()
        {
            DataTable table = SQLAccess.GreatDs("select * from DB_Flash where modelid=" + fun.banner("") + " order by flashid asc").Tables[0];
            if (table.Rows.Count > 0)
            {
                string sFlashUrl = string.Empty;
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    if (i < table.Rows.Count )
                    {
                        if (table.Rows[i]["flashurl"] == null || table.Rows[i]["flashurl"].ToString() == "")
                        {
                            sFlashUrl = "#";
                        }
                        else
                        {
                            sFlashUrl = table.Rows[i]["flashurl"].ToString() ;
                        }

                        this.imgLink = this.imgLink + " <li><a href='" + sFlashUrl + "' target='blank'><img src='../uploadfile/" + table.Rows[i]["flashpic"].ToString().Replace(@"\", "/") + "'/></a></li>";
                        this.imgNumber = this.imgNumber + "<li>" + (i+1).ToString() + "</li>"; 
                    }
                    //else if (i == (table.Rows.Count - 1))
                    //{
                    //    this.imgLink = this.imgLink + " <li><a href='" + "../uploadfile/" + table.Rows[i]["flashpic"].ToString().Replace(@"\", "/") + "'><img src='" + table.Rows[i]["flashurl"].ToString() + "'/></a></li>";
                    //    this.imgNumber = this.imgNumber + "<li>" + (i+1).ToString() + "</li>"; 
                    //}
                }
            }
            table = SQLAccess.GreatDs(string.Concat(new object[] { "select top ", Convert.ToInt32(info.info1("", "homeshownnum")), " newsid,newsname,typeid from DB_News where typeid in(", re.returnnewstype("2", "2", "1"), ") and visible=1 and isnew=1 order by newsorder,updatetime desc" })).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    string newsmsg = this.newsmsg;
                    this.newsmsg = newsmsg + "<li><a href='news_01.aspx?tid=" + row["typeid"].ToString() + "&nid=" + row["newsid"].ToString() + "' title='" + row["newsname"].ToString() + "'>" + fun.Left(row["newsname"].ToString(), 13) + "..</a></li>";
                }
            }
            string sql = "select pic,shuxiname from DB_Shuxintype where shuxinid=1";
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                this.hotpic1 = table.Rows[0][0].ToString();
                this.hottitle1 = table.Rows[0][1].ToString();
            }
            int num2 = Convert.ToInt32(info.info1("", "shopnum2"));
            int num3 = Convert.ToInt32(info.info1("", "homeshowpnum1"));
         
            int num5 = Convert.ToInt32(info.info1("", "homeshowpnum3"));
            table = SQLAccess.GreatDs("select top " + num2 + " proid,proname,proprice1,proprice3,propic2,typeid,proisnew2,proisnew3,proisnew4 from DB_Shoppro where visible=1 and proisshow=1 and proisnew1=1 and isnull(proku1,0)>0 order by proorder").Tables[0];
            if (table.Rows.Count > 0)
            {
                int num6 = 0;
                foreach (DataRow row2 in table.Rows)
                {
                    string sSid = string.Empty;
                    if (row2["proisnew2"].ToString().ToLower() == "true")
                    {
                        sSid = "2";
                    }
                    else if (row2["proisnew3"].ToString().ToLower() == "true")
                    {
                        sSid = "3";
                    }
                    else if (row2["proisnew4"].ToString().ToLower() == "true")
                    {
                        sSid = "4";
                    }
                    else
                    {
                        sSid = "1";
                    }

                    this.hotmsg1 = this.hotmsg1 + "<td valign='top'>";
                    string str4 = this.hotmsg1;
                    this.hotmsg1 = str4 + "<p><a href='products_details.aspx?pid=" + row2["proid"].ToString() + "&sid=" + sSid + "'><img src=../uploadfile/product/" + row2["propic2"].ToString() + " width='110px' /></a></p>";
                    this.hotmsg1 = this.hotmsg1 + "<ul>";
                    string str5 = this.hotmsg1;
                    this.hotmsg1 = str5 + "<li style='height:36px'><a href='products_details.aspx?pid=" + row2["proid"].ToString() + "&sid=" + sSid + "' title='" + row2["proname"].ToString() + "'>" + fun.Left(row2["proname"].ToString(), 15) + "</a></li>";
                    string sPriceName = "";
                    if (row2["proisnew3"].ToString().ToLower() == "true") {sPriceName = "零售价:"; }else{ sPriceName = "兑换价";}
                    this.hotmsg1 = this.hotmsg1 + "<li style='height:18px' class='text_red'>" + sPriceName + string.Format("{0:f}", row2["proprice1"]) + "</li>";
                  //  this.hotmsg1 = this.hotmsg1 + "<li class='text03'>市场价:" + string.Format("{0:f}", row2["proprice3"]) + "</li>";
                 
                    this.hotmsg1 = this.hotmsg1 + "</ul>";
                    this.hotmsg1 = this.hotmsg1 + "</td>";
                    num6++;
                    if (num6 >= num2)
                    {
                        break;
                    }
                    if ((num6 % 6) == 0)
                    {

                        this.hotmsg1 = this.hotmsg1 + "</tr><tr>";

                    }

                }
            }
            sql = "select shuxiname,pic from DB_Shuxintype where shuxinid=2";
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                this.hottitle2 = table.Rows[0][0].ToString();
                this.hotpic2 = table.Rows[0][1].ToString();
            }
            table = SQLAccess.GreatDs("select top " + num3 + " proid,proname,proprice1,proprice3,propic2,typeid from DB_Shoppro where visible=1 and proisshow=1 and proisnew2=1 and isnull(proku1,0)>0 order by proorder").Tables[0];
            if (table.Rows.Count > 0)
            {
                int num7 = 0;
                foreach (DataRow row3 in table.Rows)
                {
                    this.hotmsg2 = this.hotmsg2 + "<td valign='top'>";
                    string str6 = this.hotmsg2;
                    this.hotmsg2 = str6 + "<p><a href='products_details.aspx?pid=" + row3["proid"].ToString() + "&sid=2'><img src=../uploadfile/product/" + row3["propic2"].ToString() + " width='110px' /></a></p>";
                    this.hotmsg2 = this.hotmsg2 + "<ul>";
                    string str7 = this.hotmsg2;
                    this.hotmsg2 = str7 + "<li style='height:36px'><a href='products_details.aspx?pid=" + row3["proid"].ToString() + "&sid=2' title='" + row3["proname"].ToString() + "'>" + fun.Left(row3["proname"].ToString(), 15) + "</a></li>";

                    this.hotmsg2 = this.hotmsg2 + "<li style='height:18px' class='text_red'>兑换价:" + string.Format("{0:f}", row3["proprice1"]) + "</li>"; 
                  // this.hotmsg2 = this.hotmsg2 + "<li class='text03'>市场价:" + string.Format("{0:f}", row3["proprice3"]) + "</li>";
                   
                    this.hotmsg2 = this.hotmsg2 + "</ul>";
                    this.hotmsg2 = this.hotmsg2 + "</td>";
                    num7++;
                    if (num7 >= num3)
                    {
                        break;
                    }
                    if ((num7 % 8) == 0)
                    {
                        
                        this.hotmsg2 = this.hotmsg2 + "</tr><tr>";
                        
                    }
                }
            }
            sql = "select shuxiname,pic from DB_Shuxintype where shuxinid=3";
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                this.hottitle3 = table.Rows[0][0].ToString();
                this.hotpic3 = table.Rows[0][1].ToString();
            }
         
            sql = "select shuxiname,pic from DB_Shuxintype where shuxinid=4";
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                this.hottitle4 = table.Rows[0][0].ToString();
                this.hotpic4 = table.Rows[0][1].ToString();
            }
            table = SQLAccess.GreatDs("select top " + num5 + " proid,proname,proprice1,proprice3,propic2,typeid from DB_Shoppro where visible=1 and proisshow=1 and proisnew4=1 and isnull(proku1,0)>0 order by proorder").Tables[0];
            if (table.Rows.Count > 0)
            {
                int num9 = 0;
                foreach (DataRow row5 in table.Rows)
                {
                    this.hotmsg4 = this.hotmsg4 + "<td valign='top'>";
                    string str10 = this.hotmsg4;
                    this.hotmsg4 = str10 + "<p><a href='products_details.aspx?pid=" + row5["proid"].ToString() + "&sid=4'><img src=../uploadfile/product/" + row5["propic2"].ToString() + " width='110px'  /></a></p>";
                    this.hotmsg4 = this.hotmsg4 + "<ul>";
                    string str11 = this.hotmsg4;
                    this.hotmsg4 = str11 + "<li style='height:36px'><a href='products_details.aspx?pid=" + row5["proid"].ToString() + "&sid=4' title='" + row5["proname"].ToString() + "'>" + fun.Left(row5["proname"].ToString(), 15) + "</a></li>";
                    this.hotmsg4 = this.hotmsg4 + "<li style='height:18px' class='text_red'>兑换价:" + string.Format("{0:f}", row5["proprice1"]) + "</li>";
                   // this.hotmsg4 = this.hotmsg4 + "<li class='text03'>市场价:" + string.Format("{0:f}", row5["proprice3"]) + "</li>";
                  
                    this.hotmsg4 = this.hotmsg4 + "</ul>";
                    this.hotmsg4 = this.hotmsg4 + "</td>";
                    num9++;
                    if (num9 >= num5)
                    {
                        break;
                    }
                    if ((num9 % 8) == 0)
                    {
                        this.hotmsg4 = this.hotmsg4 + "</tr><tr>";
                    }
                }
            }
            DataTable table4 = new DALTopic().GetLitstByPageAndDirection("首页", "横向");
            if (table4 != null && table4.Rows.Count > 1)
            {

                if (table4.Rows[1]["picurl"].ToString() != "")
                {

                    TopicHtml = "<a href='" + table4.Rows[1]["picurl"].ToString() + "?tid=" + table4.Rows[1]["topicid"].ToString() + "' target='_blank'><img src='../uploadFile/topic/"
                        + table4.Rows[1]["pic"].ToString() + "' border='0' width='964px' /></a>";
                }
                else
                {
                    TopicHtml = "<img src='../uploadFile/topic/"
                        + table4.Rows[1]["pic"].ToString() + "' border='0' width='964px' />";
                }
            }


            ////品牌
            //int iNumBrand = 0;
            //DataTable tbBrand = SQLAccess.GreatDs("select  pinpaiid, pinpainame, pinpaiurl, pinpailogo, pinpaicontent, pinpaiorder, visible, pinpainameen, pinpaicontenten, languages, isnew, bigPic FROM  DB_Pinpai where isnew=1").Tables[0];
            //if (tbBrand.Rows.Count > 0)
            //{
            //    StringBuilder sbBrand = new StringBuilder();
            //    foreach (DataRow row in tbBrand.Rows)
            //    {


            //        sbBrand.Append("<td valign='top'>");
            //        if (row["pinpaiurl"].ToString() == "http://")
            //        {
            //            sbBrand.Append(string.Format("<p><img src=../uploadfile/brand/{0} width='90px' alt='{1}' /></p>", row["bigPic"].ToString(), row["pinpainame"].ToString()));
            //        }
            //        else
            //        {
            //            sbBrand.Append(string.Format("<p><a href='{0}' target='blank'><img src=../uploadfile/brand/{1} width='90px' alt='{2}' /></a></p>", row["pinpaiurl"].ToString(), row["bigPic"].ToString(), row["pinpainame"].ToString()));
            //        }
                   

            //        sbBrand.Append( "</td>");
            //        iNumBrand++;
            //        if (iNumBrand >= tbBrand.Rows.Count)
            //        {
            //            break;
            //        }
            //        if ((iNumBrand % 8) == 0)
            //        {
            //            sbBrand.Append("</tr><tr>");
            //        }

            //    }
            //    this.BrandHtml = sbBrand.ToString();
            //}



        }


        void BuildCardList()
        {
            Dictionary<int, string> dicInstitutionMenu = new Dictionary<int, string>();
            dicInstitutionMenu = theInstitution.GetInstitutionMenuList();

            foreach (int key in dicInstitutionMenu.Keys)
            {

                int num4 = Convert.ToInt32(info.info1("", "homeshowpnum2"));
                StringBuilder sbContent = new StringBuilder();
                DataTable table = SQLAccess.GreatDs("select top " + num4 + " proid,proname,proprice1,proprice3,propic2,typeid from DB_Shoppro where visible=1 and proisshow=1 and isnull(institutionId,0)=" + key + " and proisnew3=1 and isnull(proku1,0)>0 order by proorder").Tables[0];
                if (table.Rows.Count > 0)
                {
                    int num8 = 0;
  
                    foreach (DataRow row4 in table.Rows)
                    {
                        sbContent.Append("    <td valign='top'>");
                        sbContent.Append("<p><a href='products_details.aspx?pid=" + row4["proid"].ToString() + "&sid=3'><img src=../uploadfile/product/" + row4["propic2"].ToString() + " width='110px'  /></a></p>");
                        sbContent.Append("<ul>");
                        sbContent.Append("<li style='height:36px'><a href='products_details.aspx?pid=" + row4["proid"].ToString() + "&sid=3' title='" + row4["proname"].ToString() + "'>" + fun.Left(row4["proname"].ToString(), 15) + "</a></li>");

                        sbContent.Append("<li style='height:18px' class='text_red'>零售价:" + string.Format("{0:f}", row4["proprice1"]) + "</li>");

                        sbContent.Append("</ul>");
                        sbContent.Append("</td>");
                        num8++;
                        if (num8 >= table.Rows.Count)
                        {
                            break;
                        }
                        if ((num8 % 6) == 0)
                        {
                            sbContent.Append("</tr><tr>");
                        }
                    }
   
                    sbCardListHtml.Append(string.Format(sCardHtmlFormat
                                                         , dicInstitutionMenu[key]
                                                         , sbContent.ToString()
                                                         ));
                }
            }

            this.divCardList.InnerHtml = sbCardListHtml.ToString();
           
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            Session["backHref"] = Request.Url.PathAndQuery;
            if (!base.IsPostBack)
            {
              //  this.browesProduct1.ClientIP = this.ClientIP;
                this.Bind();
                this.BuildCardList();
            }
        }

    }
}